﻿using System;

namespace Log.Recorder.Snowflake
{
    /// <summary>
    /// 雪花算法ID生成器
    /// </summary>
    public sealed class SnowflakeWorker
    {
        private static IdWorker worker = new IdWorker(1, 1, 1);

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static long CreateId() {
            return worker.NextId();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static string CreateStringId()
        {
            return Convert.ToString(worker.NextId());
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="workerId">机器ID</param>
        /// <param name="datacenterId">机房ID</param>
        /// <param name="sequence">序列号</param>
        /// <returns></returns>
        public static long CreateId(long workerId, long datacenterId, long sequence = 0L)
        {
            return new IdWorker(workerId, datacenterId, sequence).NextId();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="workerId">机器ID</param>
        /// <param name="datacenterId">机房ID</param>
        /// <param name="sequence">序列号</param>
        /// <returns></returns>
        public static string CreateStringId(long workerId, long datacenterId, long sequence = 0L)
        {
            return Convert.ToString(CreateId(workerId, datacenterId, sequence));
        }

    }
}